/**
 * 
 */
package com.antilia.infomaresme.data.dao.impl;

import java.beans.IntrospectionException;
import java.util.List;

import com.antilia.infomaresme.DataInitialiser;
import com.antilia.infomaresme.Module;
import com.antilia.infomaresme.data.dao.interfaces.ICategoriesDao;
import com.antilia.infomaresme.data.dataobjects.Category;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.EntityNotFoundException;
import com.google.appengine.api.datastore.Key;

/**
 * @author Ernesto
 *
 */
public class GaeCategoriesDao implements ICategoriesDao {

	/**
	 * 
	 */
	public GaeCategoriesDao() {
		// TODO Auto-generated constructor stub
	}

	/* (non-Javadoc)
	 * @see com.antilia.infomaresme.data.dao.interfaces.IDao#delete(com.antilia.infomaresme.data.dataobjects.DomainObject)
	 */
	@Override
	public void delete(Category o) {
	}

	/* (non-Javadoc)
	 * @see com.antilia.infomaresme.data.dao.interfaces.IDao#load(java.io.Serializable)
	 */
	@Override
	public Category load(Key id) {
		try {
			Entity entity  = Module.getDatastoreService().get(id);
			return getCategory(entity);
		} catch (EntityNotFoundException e) {
			
		}
		return null;
	}
	
	protected Category getCategory(Entity entity) {
		Category category = new Category();
		try {
			BeanPopulator.populateBean(category, entity);
		} catch (IntrospectionException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
		return category;
	}
	
	

	/* (non-Javadoc)
	 * @see com.antilia.infomaresme.data.dao.interfaces.IDao#save(com.antilia.infomaresme.data.dataobjects.DomainObject)
	 */
	@Override
	public void save(Category o) {
		
	}

	/* (non-Javadoc)
	 * @see com.antilia.infomaresme.data.dao.interfaces.IDao#findAll()
	 */
	@Override
	public List<Category> findAll() {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see com.antilia.infomaresme.data.dao.interfaces.IDao#countAll()
	 */
	@Override
	public int countAll() {
		// TODO Auto-generated method stub
		return 0;
	}

	/* (non-Javadoc)
	 * @see com.antilia.infomaresme.data.dao.interfaces.ICategoriesDao#findTopLevel()
	 */
	@Override
	public List<Category> findTopLevel() {		
		return DataInitialiser.CATEGORIES;
	}

	/* (non-Javadoc)
	 * @see com.antilia.infomaresme.data.dao.interfaces.ICategoriesDao#findTopLevelGeographic()
	 */
	@Override
	public List<Category> findTopLevelGeographic() {
		return DataInitialiser.REGIONES;
	}

}
